Learn R Programming

VeryLargeIntegers (version 0.2.1)

05. Efficent division by a power of 2: Efficient Division by a Power of 2

Description

divp2 efficiently divides an object of class vli by a power of 2.

Usage

# S3 method for vli
divp2(x, k)

# S3 method for default divp2(x, k)

# S3 method for numeric divp2(x, k)

# S3 method for vli divp2(x, k)

Value

object of class vli

Arguments

x

dividend; object of class vli or 32 bits integer

k

exponent of the divisor (the divisor will be 2^k); 32 bits integer

Author

Javier Leiva Cuadrado

Details

Given two integers x (vli or 32 bits integer) and k (32 bits integer), the function divp2(x, k) computes and returns x/(2^k) as an object of class vli.

Examples

Run this code
# Dividing a random 500 digits integer by 2^10 = 1024
x <- rvlidigits(500)
x
divp2(x, 10)

Run the code above in your browser using DataLab